"""doc"""

from collections import OrderedDict
from rest_framework.serializers import ModelSerializer, DateTimeField, Field


class BaseSerializer(ModelSerializer):
    created_at = DateTimeField(
        format="%Y-%m-%d %H:%M:%S", required=False, read_only=True
    )
    updated_at = DateTimeField(
        format="%Y-%m-%d %H:%M:%S", required=False, read_only=True
    )


class ChoicesField(Field):
    def __init__(self, choices, **kwargs):
        """init."""
        self._choices = OrderedDict(choices)
        super(ChoicesField, self).__init__(**kwargs)

    def to_representation(self, obj):
        return self._choices[obj]
